package com.xp.code.init;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.xp.code.util.CommonConfig;

/**
 * @author HAHA
 * 
 */
public class XPWebServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static org.apache.log4j.Logger loger = org.apache.log4j.Logger
			.getLogger(XPWebServlet.class);

	/**
	 * Init Startup Servlet
	 */
	@Override
	public void init() throws ServletException {
		super.init();

		try {
			System.out.println("--------------------------");
			System.out.println("XPCode WebService init ...");

			String strRealPath = this.getServletContext().getRealPath("/");
			System.setProperty("XPCode_Home", strRealPath);
			String strSepInfo = System.getProperty("file.separator", "");
			if (!(strRealPath.substring(strRealPath.length() - 1))
					.equals(strSepInfo)) {
				strRealPath += strSepInfo;
			}
			CommonConfig.getCommonConfig();
			System.out.println("XPCode Root Directory = " + strRealPath);
			System.out.println("XPCode WebService init success");
			System.out.println("--------------------------");
		} catch (Exception e) {
			System.out.println("XPCode WebService init fail");
			e.printStackTrace();
			System.out.println("--------------------------");

			loger.error(e.getMessage());
		}
	}

}
